package org.cypress.rtpack.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.cypress.rtpack.VO.SimRep;
import org.cypress.rtpack.common.core.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author getty
 */
@RestController
@RequestMapping("/wall")
public class WallController {
    private static final Logger logger = LoggerFactory.getLogger(WallController.class);

    @PostMapping("/try_passing")
    public Result<SimRep> AskLogIn(@RequestBody String rawJson) {
        SimRep simRep = new SimRep();
        try {
            // 1. 创建 ObjectMapper 实例
            ObjectMapper objectMapper = new ObjectMapper();
            // 2. 将 JSON 字符串转换为 Java 对象（例如 Map 或自定义 DTO）
            Map<String, Object> jsonMap = objectMapper.readValue(rawJson, Map.class);
            String uid = jsonMap.get("uid").toString();
            String unk = jsonMap.get("unk").toString();

            // 验证必填字段
            if (uid.equals("admin") && unk.equals("admin365")) {
                simRep.setCode(0);
                simRep.setMsg("success");
                simRep.setRet("success");
                return Result.dataOf(simRep);
            }
            else{
                simRep.setCode(0);
                simRep.setMsg("Fail");
                simRep.setRet("Fail");
            }
        }
        catch (Exception e){
            simRep.setCode(1);
            simRep.setMsg("Fail");
            simRep.setRet("Fail");
        }
        return Result.dataOf(simRep);
    }

}
